#!/usr/bin/env python3

from quick2wire.i2c import I2CMaster, writing_bytes, reading
import time

address = 0x20
iodir_register = 0x00
gpio_register = 0x09

with I2CMaster() as master:    
    master.transaction(
        writing_bytes(address, iodir_register, 0xFF))
	
    while True:    
        read_results = master.transaction(
            writing_bytes(address, gpio_register),
            reading(address, 1))
        
        gpio_state = read_results[0][0]
        
        print("%02x" % gpio_state)
        
        time.sleep(1)
